package cn.codesugar.videocache

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import cn.codesugar.videocache.databinding.ActivityVideoGalleryBinding

class VideoGalleryActivity : AppCompatActivity() {

    private lateinit var binding: ActivityVideoGalleryBinding
    private val urlList: List<String> = listOf(
        "https://codesugar.cn/res/%E4%B9%90%E9%AB%98%E5%A4%A7%E7%94%B5%E5%BD%B1%E9%A2%84%E5%91%8A.mp4",
        "https://codesugar.cn/res/%E5%A5%A5%E8%BF%AAA4.mp4",
        "https://codesugar.cn/res/%E6%83%8A%E5%A5%87%E9%98%9F%E9%95%BF%E9%A2%84%E5%91%8A.mp4",
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityVideoGalleryBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.viewPager.adapter = ViewsPagerAdapter(this)
    }

    inner class ViewsPagerAdapter(fragmentActivity: FragmentActivity) : FragmentStateAdapter(fragmentActivity) {

        override fun getItemCount() = urlList.size


        override fun createFragment(position: Int): Fragment {
            return GalleryVideoFragment.newInstance(urlList[position])
        }

    }
}